<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>zut Chat 管理员登录</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #07c160 0%, #06ae56 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }
        
        .login-container {
            background: #ffffff;
            border-radius: 16px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
            padding: 40px;
            width: 100%;
            max-width: 400px;
            position: relative;
            overflow: hidden;
        }
        
        .login-container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #07c160, #06ae56);
        }
        
        .logo-section {
            text-align: center;
            margin-bottom: 40px;
        }
        
        .logo-icon {
            width: 64px;
            height: 64px;
            background: linear-gradient(135deg, #07c160, #06ae56);
            border-radius: 16px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 16px;
            box-shadow: 0 8px 24px rgba(7, 193, 96, 0.3);
        }
        
        .logo-icon i {
            color: white;
            font-size: 28px;
        }
        
        .logo-title {
            font-size: 24px;
            font-weight: 600;
            color: #191919;
            margin-bottom: 8px;
        }
        
        .logo-subtitle {
            font-size: 14px;
            color: #969696;
        }
        
        .form-group {
            margin-bottom: 24px;
            position: relative;
        }
        
        .form-label {
            display: block;
            font-size: 14px;
            font-weight: 500;
            color: #191919;
            margin-bottom: 8px;
        }
        
        .form-input {
            width: 100%;
            height: 48px;
            border: 2px solid #e7e7e7;
            border-radius: 12px;
            padding: 0 16px 0 48px;
            font-size: 16px;
            color: #191919;
            background: #ffffff;
            transition: all 0.2s ease;
        }
        
        .form-input:focus {
            outline: none;
            border-color: #07c160;
            box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.1);
        }
        
        .form-icon {
            position: absolute;
            left: 16px;
            top: 50%;
            transform: translateY(-50%);
            color: #969696;
            font-size: 16px;
        }
        
        .form-group:has(.form-input:focus) .form-icon {
            color: #07c160;
        }
        
        .login-btn {
            width: 100%;
            height: 48px;
            background: linear-gradient(135deg, #07c160, #06ae56);
            border: none;
            border-radius: 12px;
            color: white;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        
        .login-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 24px rgba(7, 193, 96, 0.4);
        }
        
        .login-btn:active {
            transform: translateY(0);
        }
        
        .login-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        
        .login-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: left 0.5s;
        }
        
        .login-btn:hover::before {
            left: 100%;
        }
        
        .error-message {
            background: #fee;
            color: #d63031;
            padding: 12px 16px;
            border-radius: 8px;
            font-size: 14px;
            margin-bottom: 20px;
            border-left: 4px solid #d63031;
            display: none;
        }
        
        .success-message {
            background: #e8f5e8;
            color: #07c160;
            padding: 12px 16px;
            border-radius: 8px;
            font-size: 14px;
            margin-bottom: 20px;
            border-left: 4px solid #07c160;
            display: none;
        }
        
        .loading-spinner {
            display: none;
            margin-right: 8px;
        }
        
        .loading-spinner i {
            animation: spin 1s linear infinite;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .footer-text {
            text-align: center;
            margin-top: 32px;
            font-size: 12px;
            color: #969696;
        }
        
        @media (max-width: 480px) {
            .login-container {
                padding: 24px;
                margin: 20px;
            }
            
            .logo-title {
                font-size: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="logo-section">
            <div class="logo-icon">
                <i class="fas fa-shield-alt"></i>
            </div>
            <h1 class="logo-title">管理员登录</h1>
            <p class="logo-subtitle">zut Chat 后台管理系统</p>
        </div>
        
        <form id="loginForm">
            <div class="error-message" id="errorMessage"></div>
            <div class="success-message" id="successMessage"></div>
            
            <div class="form-group">
                <label class="form-label" for="username">用户名</label>
                <div style="position: relative;">
                    <i class="form-icon fas fa-user"></i>
                    <input type="text" id="username" name="username" class="form-input" placeholder="请输入管理员用户名" required>
                </div>
            </div>
            
            <div class="form-group">
                <label class="form-label" for="password">密码</label>
                <div style="position: relative;">
                    <i class="form-icon fas fa-lock"></i>
                    <input type="password" id="password" name="password" class="form-input" placeholder="请输入密码" required>
                </div>
            </div>
            
            <button type="submit" class="login-btn" id="loginBtn">
                <span class="loading-spinner" id="loadingSpinner">
                    <i class="fas fa-spinner"></i>
                </span>
                登录
            </button>
        </form>
        
        <div class="footer-text">
            默认账号：admin / yxq666
        </div>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value.trim();
            const loginBtn = document.getElementById('loginBtn');
            const loadingSpinner = document.getElementById('loadingSpinner');
            const errorMessage = document.getElementById('errorMessage');
            const successMessage = document.getElementById('successMessage');
            
            if (!username || !password) {
                showError('请输入用户名和密码');
                return;
            }
            
            // 显示加载状态
            loginBtn.disabled = true;
            loadingSpinner.style.display = 'inline-block';
            hideMessages();
            
            try {
                const response = await fetch('/api/auth/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ username, password })
                });
                
                const data = await response.json();
                
                if (data.success) {
                    showSuccess('登录成功，正在跳转...');
                    setTimeout(() => {
                        window.location.href = '/backend';
                    }, 1000);
                } else {
                    showError(data.message || '登录失败');
                }
            } catch (error) {
                console.error('登录错误:', error);
                showError('网络错误，请稍后重试');
            } finally {
                loginBtn.disabled = false;
                loadingSpinner.style.display = 'none';
            }
        });
        
        function showError(message) {
            const errorMessage = document.getElementById('errorMessage');
            errorMessage.textContent = message;
            errorMessage.style.display = 'block';
            document.getElementById('successMessage').style.display = 'none';
        }
        
        function showSuccess(message) {
            const successMessage = document.getElementById('successMessage');
            successMessage.textContent = message;
            successMessage.style.display = 'block';
            document.getElementById('errorMessage').style.display = 'none';
        }
        
        function hideMessages() {
            document.getElementById('errorMessage').style.display = 'none';
            document.getElementById('successMessage').style.display = 'none';
        }
        
        // 检查是否已经登录
        fetch('/api/auth/check')
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    window.location.href = '/backend';
                }
            })
            .catch(error => {
                console.log('未登录');
            });
    </script>
</body>
</html> 